package com.rrd.itext.xmlBean.converter;

import com.itextpdf.text.pdf.codec.Base64;
import com.rrd.itext.utils.HTMLParser;
import com.rrd.itext.utils.HtmlDeserializer;
import com.rrd.itext.xmlBean.layoutBean.XmlHtmlBlock;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class HtmlBlockConverter implements Converter {
    public void marshal(Object obj, HierarchicalStreamWriter writer, MarshallingContext context) {
    }

	@Override
	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		XmlHtmlBlock htmlBlock = new XmlHtmlBlock();

        String printOrderStr = reader.getAttribute("printOrder");
        String newLineStr = reader.getAttribute("newLine");
		htmlBlock.setName(reader.getAttribute("name"));

    	if(printOrderStr != null && !"".equals(printOrderStr)){
    	    htmlBlock.setPrintOrder(Integer.valueOf(printOrderStr));
    	}
    	if(newLineStr != null && "true".equalsIgnoreCase(newLineStr)){
    	    htmlBlock.setNewLine(true);
    	}else{
    	    htmlBlock.setNewLine(false);
    	}
        return htmlBlock;
    }

    public boolean canConvert(Class clazz) {
        return clazz.equals(XmlHtmlBlock.class);
    }
}
